/*
 * Copyright 2011 Raimon Rodriguez
 *
 * This file is part of sgfx.
 *
 * sgfx is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * sgfx is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with sgfx. If not, see <http://www.gnu.org/licenses/>.
 */

package com.googlecode.sgfx.controller;

import com.googlecode.sgfx.base.Log;
import java.io.IOException;
import java.util.logging.LogManager;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.SwingUtilities;
import javax.swing.TransferHandler;

/**
 *
 * @author raimon.rodriguez
 */
public class DoubleListFrame extends JFrame {
    private static final Log log = Log.getLog(DoubleListFrame.class);
    
    
    /** Creates new form DoubleListFrame */
    public DoubleListFrame() {
        initComponents();

        sourceList.setName("sourceList");
        destList.setName("destList");
        addButton.setName("addButton");
        addAllButton.setName("addAllButton");
        removeButton.setName("removeButton");
        removeAllButton.setName("removeAllButton");
        
//        new DoubleListControllerBuilder<String>(sourceList, destList).setAddButton(addButton)
//                .setRemoveButton(removeButton).wireUp();

        // only with DnD
//        new DoubleListControllerBuilder<String>(sourceList, destList).enableDefaultDragAndDrop()
//                .wireUp();

        log.finest("TransferHandler.COPY=" + TransferHandler.COPY);
        log.finest("TransferHandler.COPY_OR_MOVE=" + TransferHandler.COPY_OR_MOVE);
        log.finest("TransferHandler.LINK=" + TransferHandler.LINK);
        log.finest("TransferHandler.MOVE=" + TransferHandler.MOVE);
        log.finest("TransferHandler.NONE=" + TransferHandler.NONE);
        
        // only with buttons
//        new DoubleListControllerBuilder<String>(sourceList, destList)
//                .setAddButton(addButton).setRemoveButton(removeButton).setAddAllButton(addAllButton)
//                .setRemoveAllButton(removeAllButton).wireUp();

        // only with some key bindings
//        new DoubleListControllerBuilder<String>(sourceList, destList)
//                .setAddKeyStroke(KeyStroke.getKeyStroke(KeyEvent.VK_EQUALS, InputEvent.CTRL_DOWN_MASK))
//                .setRemoveKeyStroke(KeyStroke.getKeyStroke(KeyEvent.VK_MINUS, InputEvent.CTRL_DOWN_MASK))
//                .wireUp();
    }

    
    public JList getSourceList() {
        return sourceList;
    }
    
    public JList getDestinationList() {
        return destList;
    }

    public JButton getAddButton() {
        return addButton;
    }

    public JButton getAddAllButton() {
        return addAllButton;
    }

    public JButton getRemoveButton() {
        return removeButton;
    }

    public JButton getRemoveAllButton() {
        return removeAllButton;
    }

    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        sourceList = new javax.swing.JList();
        jScrollPane2 = new javax.swing.JScrollPane();
        destList = new javax.swing.JList();
        addButton = new javax.swing.JButton();
        addAllButton = new javax.swing.JButton();
        removeButton = new javax.swing.JButton();
        removeAllButton = new javax.swing.JButton();
        sourceLabel = new javax.swing.JLabel();
        destinationLabel = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        sourceList.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Repeated", "Item 2", "Item 3", "Item 4", "Item 5", "Repeated" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        jScrollPane1.setViewportView(sourceList);

        jScrollPane2.setViewportView(destList);

        addButton.setText("Add");

        addAllButton.setText("Add all");

        removeButton.setText("Remove");

        removeAllButton.setText("Remove all");

        sourceLabel.setText("Source:");

        destinationLabel.setText("Destination:");

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 109, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(addButton)
                            .add(addAllButton)
                            .add(removeButton)
                            .add(removeAllButton)))
                    .add(sourceLabel))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(destinationLabel)
                    .add(jScrollPane2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 144, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        layout.linkSize(new java.awt.Component[] {jScrollPane1, jScrollPane2}, org.jdesktop.layout.GroupLayout.HORIZONTAL);

        layout.linkSize(new java.awt.Component[] {addAllButton, addButton, removeAllButton, removeButton}, org.jdesktop.layout.GroupLayout.HORIZONTAL);

        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(22, 22, 22)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(sourceLabel)
                    .add(destinationLabel))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(14, 14, 14)
                        .add(addButton)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(addAllButton)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(removeButton))
                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                        .add(layout.createSequentialGroup()
                            .add(111, 111, 111)
                            .add(removeAllButton))
                        .add(jScrollPane2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 174, Short.MAX_VALUE)
                        .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 174, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                .add(111, 111, 111))
        );

        layout.linkSize(new java.awt.Component[] {jScrollPane1, jScrollPane2}, org.jdesktop.layout.GroupLayout.VERTICAL);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    
    public static void main(String... pArgs) throws IOException {
        LogManager.getLogManager().readConfiguration(
                DoubleListFrame.class.getResourceAsStream("/config/logging.properties"));
        
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                new DoubleListFrame().setVisible(true);
            }
        });
    }


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton addAllButton;
    private javax.swing.JButton addButton;
    private javax.swing.JList destList;
    private javax.swing.JLabel destinationLabel;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JButton removeAllButton;
    private javax.swing.JButton removeButton;
    private javax.swing.JLabel sourceLabel;
    private javax.swing.JList sourceList;
    // End of variables declaration//GEN-END:variables
}